/**
 * 
 */
package com.jm.utils.xml;

import java.util.Vector;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.jm.utils.StringHelper;

/**
 * @author yanjie
 * Dec 14, 2011 11:20:25 AM
 */
public class VectorHandler extends DefaultHandler{
	public static final String VAR_ROOTNAME = "vector";
	public static final String VAR_DATANODENAME = "data";
	private Vector vector = null;
	private String value = null;
	@Override
	public void startElement(String namespaceURI,String localName,String qName,Attributes attrs) throws SAXException{  
		if(qName.equals(VAR_ROOTNAME)){
			this.vector = null;
			this.vector = new Vector();
			
		}
	}  
	 
	 // 元素结尾
	 @Override
	 public void endElement(String namespaceURI,String localName,String qName) throws SAXException{	
		//栏位名称
		if(qName.equals(VAR_DATANODENAME)){
			String[] datas = this.value.split(XmlUtils.strSplit);
			for (int i = 0; i < datas.length-1; i++) {
				this.vector.add(StringHelper.getValue(datas[i]));
			}
		}
	 }  
	 
	 // 元素中间的文本数据
	 @Override
	 public void characters(char ch[],int start,int length) throws SAXException  
	 {  
	  value = new String(ch,start,length);  
	 }  
	 
	 //文档结尾
	 public void endDocument() throws SAXException{}

	public Vector getVector() {
		return vector;
	}
}
